package cn.elwy.rcp.demo.dialog;

import java.util.List;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;

import cn.elwy.rcp.ui.table.adapter.CellModifierAdapter;
import cn.elwy.rcp.ui.table.adapter.TableEditorAdapter;
import cn.elwy.rcp.ui.table.model.ColumnInfo;

public class UserEditorAdapter extends TableEditorAdapter {

  public UserEditorAdapter() {
  }

  @Override
  public CellEditor[] getCellEditors() {
    List<ColumnInfo> columnInfoList = tableInfo.getColumnInfoList();
    CellEditor[] CellEditor = new CellEditor[columnInfoList.size()];
    for (int i = 0; i < columnInfoList.size(); i++) {
      ColumnInfo columnInfo = columnInfoList.get(i);
      if (columnInfo.isCanEditor()) {
        CellEditor[i] = new TextCellEditor((Composite) tablePane.getTable(), SWT.SINGLE);
      }
    }
    return CellEditor;
  }

  @Override
  public ICellModifier getCellModifier() {
    return new CellModifier(this);
  }

  private class CellModifier extends CellModifierAdapter {

    public CellModifier(TableEditorAdapter tableEditorAdapter) {
      super(tableEditorAdapter);
    }

    public void modify(Object element, String property, Object value) {
      super.modify(element, property, value);
    }
  }
}
